#!/bin/bash

source ../common/common.sh

echo "===INIT==UBUNTU=WEB=SERVER=AND=DB==="
sudo echo "SUDO ROOT"

tmp_ip=`get_local_ip`
tmp_install_db=""

for i in $@
do
    if [ "$i" == "local" -o "$i" == "localhost" ]; then
        tmp_ip="127.0.0.1"
    #elif [ "$i" == "localhost" ]; then
    #    tmp_install_db="127.0.0.1"
    elif [ "$i" == "db" ]; then
        tmp_install_db="db"
    elif [ "$i" == "mysql" ]; then
        tmp_install_db="db"
    fi
done

show t "安装nginx"
install_apt_pack "force|nginx"

show t "安装php-fpm"

install_apt_pack "force|php5-fpm php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-recode"
install_apt_pack "force|php5-imap php5-mcrypt php5-memcache php5-memcached php5-ming php5-ps php5-pspell"
install_apt_pack "force|php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json php5-apcu"
install_apt_pack "force|php5-cli php5 php5-common php5-dev"
install_php_mod_conf "mcrypt"
install_php_pecl "redis"

show t "重启PHP-FPM服务"
sudo service php5-fpm restart

if [ ! -z "$tmp_install_db" ]; then
  show t "安装MySQL服务"
  install_apt_pack "force|mysql-server mysql-client"
fi

show t "配置主机网站 default [$tmp_ip:80]"
create_website DEF default $tmp_ip 80 localhost/default/html php

# 演示用法
#if [ ! -z `chk_local_ip 192.168.1.111` ]; then
#  show t "配置主机网站:demo.myserver.com"
#  create_website DEMO demo.myserver.com 192.168.1.111 80 myserver.com/demo/html php 
#fi


show t "重启Nginx服务"
sudo service nginx restart
